<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="80px">
            <el-form-item label="活动名称" prop="campaignPageName">
                <el-input v-model="queryParams.campaignPageName" placeholder="请输入活动名称" clearable
                    @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
                <el-button type="success" plain icon="Plus" @click="handleAdd"
                    v-hasPermi="['decor:campaignPage:add']">新增</el-button>
            </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="campaignPageList">
            <el-table-column label="ID" align="center" prop="campaignPageId" />
            <el-table-column label="活动名称" :show-overflow-tooltip="true" align="center"
                prop="campaignPageName"></el-table-column>
            <el-table-column label="活动状态" align="center" prop="status">
                <template #default="scope">
                    <dict-tag :options="status" :value="scope.row.status" />
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template #default="scope">
                    <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['decor:campaignPage:edit']">修改</el-button>
                    <el-button link type="warning" icon="Delete" @click="handleDelete(scope.row)"
                        v-hasPermi="['decor:campaignPage:remove']">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize" @pagination="getList" />
    </div>
</template>
<script setup>
import { listCampaignPage, delCampaignPage } from "@/api/decor/advertisement";
const router = useRouter();
const { proxy } = getCurrentInstance();
const { status } = proxy.useDict('status');
// 表格数据
const campaignPageList = ref([]);
// 遮罩层
const loading = ref(true);
// 显示搜索条件
const showSearch = ref(true);
// 总条数
const total = ref(0);

const data = reactive({
    queryParams: {
        pageNum: 1,
        pageSize: 10,
        campaignPageName: null,
        campaignPageStructure: null,
        status: null,
        orderNum: null,
    },
});
const { queryParams} = toRefs(data);
/** 查询活动页列表 */
function getList() {
    loading.value = true;
    listCampaignPage(queryParams.value).then(response => {
        campaignPageList.value = response.rows;
        total.value = response.total;
        loading.value = false;
    });
}
/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
}

/** 重置按钮操作 */
function resetQuery() {
    proxy.resetForm("queryRef");
    handleQuery();
}

/** 新增按钮操作 */
function handleAdd() {
    router.push("/advertisement/activeEdit");
}

/** 修改按钮操作 */
function handleUpdate(row) {
    router.push("/advertisement/activeEdit/" + row.campaignPageId);
}
/** 删除按钮操作 */
function handleDelete(row) {
    proxy.$modal.confirm('是否确认删除活动名称为"' + row.campaignPageName + '"的数据？').then(function () {
        return delCampaignPage(row.campaignPageId);
    }).then(() => {
        getList();
        proxy.$modal.msgSuccess("删除成功");
    }).catch(() => { });
}

getList()
</script>
<style lang="scss" scoped>
.adv {
    margin: 20px;
}
</style>